function content0LoadFunction() {
	renderAdministratorGrid();
}	

function addUser() {
	// Turn off add button
	$('buttonNew').style.display = 'none';
	
	// Set hidden field defaults
	$('formAction').value = 'add';
	$('uID').value = '0';
			
	// Display add form
	new Effect.SlideDown('formNewUser', {direction: 'top', duration: .3});		
}

function saveUser() {
	var fullName  = $('uUserFullName').value;
	var email     = $('uEmail').value;
	var userid    = $('uUserNameBox').value;
	var password  = $('uPassword').value;
	var passwordConfirm = $('uPasswordConfirm').value;
	var userLevel = $('uUserLevel').options;
	var userLevel = userLevel[userLevel.selectedIndex].value;
	
	// Check for errors
	if (password != passwordConfirm) {
		var error = 1;
		var message = 'Administrator password was not confirmed.';
		updateStatus(message,'error','statusDiv');
	} else {
		var phpString = fullName+'|'+email+'|'+userid+'|'+password+'|'+userLevel;
		x_saveUser(phpString,returnSaveUser);
	}
}

function returnSaveUser() {
	var message = 'Administrator has been added.';
	updateStatus(message,'success','statusDiv');
	cancelUser();
	
	renderAdministratorGrid();
	
}

function cancelUser() {
	// Display add form
	new Effect.SlideUp('formNewUser', {direction: 'top', duration: .2});
	
	// Clear all form elements
	$('uUserFullName').value    = '';
	$('uEmail').value           = '';
	$('uUserNameBox').value     = '';
	$('uPassword').value        = '';
	$('uPasswordConfirm').value = '';
	
	// Turn on add button
	$('buttonNew').style.display = 'block';	
}

function renderAdministratorGrid() {
	// shorthand alias
    var fm = Ext.form;
	var Ed = Ext.grid.GridEditor;
	
	// Create the data source
	var ds = new Ext.data.Store({
	    proxy: new Ext.data.HttpProxy({
			url: 'includes/sajax/sajaxUsers.php?getUsers=1'
	    }),
		
	    reader: new Ext.data.JsonReader({
	        root: 'Administrators',
	        id: 'UID'
	    }, [
	    {name: 'UID', mapping: 'UID'},
		{name: 'Delete', mapping: 'Delete'},
	    {name: 'FullName', mapping: 'FullName'},
		{name: 'Email', mapping: 'Email'},
		{name: 'Userid', mapping: 'Userid'},
		{name: 'Password', mapping: 'Password'},
		{name: 'AdminLevel', mapping: 'AdminLevel'}
	    ])		
	});
	ds.load();

	// Define the column model
	var colModel = new Ext.grid.ColumnModel([
		{dataIndex: 'UID', hidden: 'true'}
		,{dataIndex: 'Delete', align: 'center', width: 40, header: ""}
		,{
		 	header:    "Name", 
			width:     200, 
			sortable:  true, 
			dataIndex: 'FullName',
			editor: new Ed(new fm.TextField({
            	allowBlank: true
           	}))
		}
		,{
			header: "Email Address", 
			align: 'left', 
			width: 200, 
			sortable: true, 
			dataIndex: 'Email',
			editor: new Ed(new fm.TextField({
            	allowBlank: true
           	}))
		}
		,{
			header: "User Name", 
			width: 100, 
			sortable: true, 
			dataIndex: 'Userid',
			editor: new Ed(new fm.TextField({
            	allowBlank: true
           	}))
		}
		,{
			header: "Password", 
			width: 100, 
			sortable: true, 
			dataIndex: 'Password',
			editor: new Ed(new fm.TextField({
            	allowBlank: true
           	}))
		}
		,{
			header: "User Level", 
			width: 100, 
			sortable: true, 
			dataIndex: 'AdminLevel',
			editor: new Ed(new Ext.form.ComboBox({
               typeAhead: true,
               triggerAction: 'all',
               transform:'uUserLevelForGrid',
               lazyRender:true
            }))
		}
	]);

    // Create the Grid
	var grid = new Ext.grid.EditorGrid('userGrid', {
        ds: ds,
        cm: colModel
    });
	
	grid.on('afteredit',saveGrid);
	function saveGrid(gridStuff) {
		var gridRow       = gridStuff.row;
		var cellValue     = gridStuff.value;
		var cellValueOrig = gridStuff.originalValue;
		var uID           = gridStuff.record.data.UID;
		var cellField     = gridStuff.field;
				
		var phpString = uID+'|'+cellValue+'|'+cellField+'|'+gridRow+'|'+cellValueOrig;
		x_editUser(phpString,returnEditUser);	
	}
			
	// make the grid resizable, do before render for better performance
    var rz = new Ext.Resizable('userGrid', {
        wrap: true,
        minHeight: 300,
        pinned: true,
        handles: 's'
    });
    rz.on('resize', grid.autoSize, grid);      
	  
	grid.render();
	grid.getView().refresh();	
}	

function returnDeleteUser(uID) {
	var message = 'Administrator has been deleted.';
	updateStatus(message,'success','statusDiv');
	
	// Refresh grid
	
}

function returnEditUser(uID) {
	var message = 'Administrator has been updated.';
	updateStatus(message,'success','statusDiv');
	
	// Refresh grid
	renderAdministratorGrid();	
}